package com.example.projectcode.controller.Teacher;

import com.example.projectcode.model.*;
import com.example.projectcode.result.Result;
import com.example.projectcode.service.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.nio.file.Path;
import java.util.List;

@Api(tags = "题目批改接口")
@RestController
@RequestMapping(value = "/teacher/answerreview")
public class AnswerReviewController {

    @Autowired
    private StudentService studentService;

    @Autowired
    private CstuanService cstuanService;

    @Autowired
    private CpstuanService cpstuanService;

    @Autowired
    private TestCstuanService testCstuanService;

    @Autowired
    private TestCpstuanService testCpstuanService;

    @Autowired
    private ChoiceService choiceService;

    @Autowired
    private ComprehensiveService comprehensiveService;

    @Autowired
    private TestchoiceService testchoiceService;

    @Autowired
    private TestcomprehensiveService testcomprehensiveService;

    @ApiOperation("选择学生")
    @GetMapping("/viewStudents")
    public Result viewstudents(){
    List<Student> studentList = studentService.selectAllStudents();
    return Result.ok(studentList);
    }

    @ApiOperation("根据类型和题目类型和学生id列出修改的题目")
    @GetMapping("/viewAnswerItems/{type}/{typeofQuestion}/{stuId}")
    public Result viewAnswerItems(@PathVariable String type,
                                  @PathVariable String typeofQuestion,
                                  @PathVariable Integer stuId){
        if (type.equals("练习题")&&typeofQuestion.equals("选择题")){
            List<Cstuan> cstuanList = cstuanService.selectAllByStuId(stuId);
            return Result.ok(cstuanList);
        }
        if (type.equals("练习题")&&typeofQuestion.equals("综合题")){
            List<Cpstuan> cpstuanList = cpstuanService.selectAllByStuId(stuId);
            return Result.ok(cpstuanList);
        }

        if (type.equals("模拟题")&&typeofQuestion.equals("选择题")){
            List<TestCstuan> testCstuanList = testCstuanService.selectAllByStuId(stuId);
            return Result.ok(testCstuanList);
        }

        if (type.equals("模拟题")&&typeofQuestion.equals("综合题")){
            List<TestCpstuan> testCpstuanList = testCpstuanService.selectAllByStuId(stuId);
            return Result.ok(testCpstuanList);
        }

        return Result.ok();

    }


    @ApiOperation("根据选择题id查看详情内容")
    @GetMapping("/viewdetailChoice/{choiceId}")
    public Result viewdetailChoice(@PathVariable Integer choiceId){
        Choice choice = choiceService.selectChoiceByCId(choiceId);
        return Result.ok(choice);
    }

    @ApiOperation("练习题选择题题目批改")
    @GetMapping("/updateCstuan/{Cstuanid}/{Cfeedback}")
    public Result updatechoice(@PathVariable Integer Cstuanid,@PathVariable String Cfeedback){
        int result = cstuanService.updateCstuanByCstuanId(Cstuanid,Cfeedback);
        if (result>0){
            return Result.ok().message("批改成功");
        }else {
            return Result.fail().message("批改失败");
        }
    }

    @ApiOperation("根据综合题题id查看详情内容")
    @GetMapping("/viewdetailComprehensive/{ComprehensiveId}")
    public Result viewdetailComprehensive(@PathVariable Integer ComprehensiveId){
       Comprehensive comprehensive = new Comprehensive();
       comprehensive = comprehensiveService.selectComprehensiveByCpId(ComprehensiveId);
        return Result.ok(comprehensive);
    }


    @ApiOperation("练习题综合题题题目批改")
    @GetMapping("/updateCpstuan/{Cpstuanid}/{Teaid}/{Teacom}")
    public Result updateComprehensive(@PathVariable Integer Cpstuanid,
                                      @PathVariable Integer Teaid,
                                      @PathVariable String Teacom){
        int result = cpstuanService.updateCpstuanById(Cpstuanid,Teaid,Teacom);
        if (result>0){
            return Result.ok().message("批改成功");
        }else {
            return Result.fail().message("批改失败");
        }
    }



    @ApiOperation("根据试卷选择题id查看详情内容")
    @GetMapping("/viewdetailTestChoice/{testchoiceId}")
    public Result viewdetailTestChoice(@PathVariable Integer testchoiceId){
         Testchoice testchoice = new Testchoice();
         testchoice = testchoiceService.selecttestchoiceById(testchoiceId);
         Choice choice = choiceService.selectChoiceByCId(testchoice.getChoiceId());
        return Result.ok(choice);
    }


    @ApiOperation("模拟题选择题题目批改")
    @GetMapping("/updatetestCstuan/{TestCstuanid}/{Cfeedback}")
    public Result updatetestchoice(@PathVariable Integer TestCstuanid,@PathVariable String Cfeedback){
        int result = testCstuanService.updatetestcstuanById(TestCstuanid,Cfeedback);
        if (result>0){
            return Result.ok().message("批改成功");
        }else {
            return Result.fail().message("批改失败");
        }
    }


    @ApiOperation("根据试卷综合题题id查看详情内容")
    @GetMapping("/viewdetailtestComprehensive/{testCpId}")
    public Result viewdetailtestCp(@PathVariable Integer testCpId){

        Testcomprehensive testcomprehensive = new Testcomprehensive();
        testcomprehensive = testcomprehensiveService.selectOneBttestCpId(testCpId);

        Comprehensive comprehensive = new Comprehensive();
        comprehensive = comprehensiveService.selectComprehensiveByCpId(testcomprehensive.getCpId());
        return Result.ok(comprehensive);
    }

    @ApiOperation("练习题综合题题题目批改")
    @GetMapping("/updateTestCpstuan/{testCpstuanid}/{Teaid}/{Teacom}")
    public Result updatetestComprehensive(@PathVariable Integer testCpstuanid,
                                      @PathVariable Integer Teaid,
                                      @PathVariable String Teacom){
        int result = testCpstuanService.updatetestCpstuanById(testCpstuanid,Teaid,Teacom);
        if (result>0){
            return Result.ok().message("批改成功");
        }else {
            return Result.fail().message("批改失败");
        }
    }











}
